// ConnectDialog.cpp : implementation file
//

#include "stdafx.h"
#include "chat_admin.h"

#include "ConnectDialog.h"
#include "afxdialogex.h"


// ConnectDialog dialog

IMPLEMENT_DYNAMIC(ConnectDialog, CDialogEx)

ConnectDialog::ConnectDialog(CWnd* pParent /*=NULL*/)
	: CDialogEx(ConnectDialog::IDD, pParent)
{
	
}

ConnectDialog::~ConnectDialog()
{
}

void ConnectDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CANCEL, m_cancel);
	DDX_Control(pDX, IDC_CONNECT, m_connect);
	DDX_Control(pDX, IDC_USERCHOSE, m_user_choose);
	DDX_Control(pDX, IDC_USER, m_user_text);

	DDX_Control(pDX, IDC_BUTTON_LOGIN, m_login);
	DDX_Control(pDX, IDC_COMBO1, m_Ip);
	m_user_choose.SetCurSel(0);
	m_Ip.SetCurSel(0);
}


BEGIN_MESSAGE_MAP(ConnectDialog, CDialogEx)
	ON_BN_CLICKED(IDC_CONNECT, &ConnectDialog::OnBnClickedConnect)
	ON_BN_CLICKED(IDC_CANCEL, &ConnectDialog::OnBnClickedCancel)
	ON_BN_CLICKED(IDC_BUTTON_LOGIN, &ConnectDialog::OnBnClickedButtonLogin)
	ON_WM_CLOSE()
END_MESSAGE_MAP()


// ConnectDialog message handlers


void ConnectDialog::OnBnClickedConnect()
{
	USES_CONVERSION;
  	WCHAR c[64]={0};
	m_Ip.GetWindowTextW(c,64);
	ChatClient* client=ChatClient::Instance(W2A(c),8888);//->Login("root",nullptr,1,1,0,"login");
	m_connect.EnableWindow(0);
	//client->Login("root",nullptr,1,1,0,"login");
}


void ConnectDialog::OnBnClickedCancel()
{
	CDialogEx::OnCancel();
	// TODO: Add your control notification handler code here
}


void ConnectDialog::OnBnClickedButtonLogin()
{
	USES_CONVERSION;
	WCHAR c[64]={0};
	m_user_choose.GetWindowTextW(c,64);
	string ss=EncodeUtf8(c);
	ChatClient::Instance()->Login(ss.c_str(),nullptr,1,1,0,"login");
	m_login.EnableWindow(0);
	
}


void ConnectDialog::OnClose()
{
	// TODO: Add your message handler code here and/or call default

	CDialogEx::OnClose();
	theApp.OnFileNewEx();
}
